/*******************************************************************************
																				
	DESCRIPTION:  	This do file produces statistics based on the ensemble predictions generated 
					for different job finding horizons in the year 2006.

*******************************************************************************/

clear all
global id_code 108_2

* Import programs:
run "${code}/Output Generation/108_0_MainStatistics_Program.do"

* Import predictions:
local vars _
local model Full
local year 2006
		
use "${data}/003_MainWithEnsemblePred_`model'`vars'2006.dta", ///


compress

* Calculate statistics:
file open myfile using "${output}/${id_code}_MainStatistics_Table_`model'`vars'`year'_DifferentJobFindingHorizons.tex", write replace

file write myfile "\documentclass{article}" _newline ///
	"\usepackage{booktabs}" _newline ///
	"\usepackage[margin=1in]{geometry}" _newline ///
	"\begin{document}" _newline ///
	"\begin{table}[h] \centering" _newline ///
	"\footnotesize \begin{tabular}{l c @{\extracolsep{16pt}} c  @{\extracolsep{8pt}} c  @{\extracolsep{16pt}} c  @{\extracolsep{8pt}} c @{\extracolsep{16pt}} c @{\extracolsep{8pt}} c @{\extracolsep{16pt}} c @{\extracolsep{8pt}} c}" _newline ///
	"\hline \hline \addlinespace[3ex]" _newline ///
	///
	" & & \multicolumn{2}{c}{\(E(\cdot)\)} & \multicolumn{2}{c}{\(Var(\cdot)\)} & \multicolumn{2}{c}{\(Cov(\cdot)\)}  & \multicolumn{2}{c}{\(R^2(\cdot)\)} \\ \addlinespace[0.1cm]" _newline ///
	" \cline{3-4} \cline{5-6} \cline{7-8} \cline{9-10} \addlinespace[1.5ex]" _newline ///
	"\textbf{Job Finding Horizon} & N & \(F\) & \(\hat{F}\) & \(F\) & \(\hat{F}\)  & \(\hat{F}, F\) & \(\hat{F}, F_{6m}\) & \(\hat{F}, F\) & \(\hat{F}, F_{6m}\) \\ \addlinespace[0.1cm]" _newline ///
	" \hline \addlinespace[1.5ex]" _newline

foreach months in 3 6 12 {
		  		
	foreach unempl in 0 {

	
		namer `months' `unempl'
		reg emplAft6M_`unempl'M_In `r(pred)'
		local r2_6m : di %9.3f `e(r2)'
		
		namer `months' `unempl'
		corr emplAft6M_`unempl'M_In `r(pred)', cov
		local cov_6m : di %9.3f `r(cov_12)'
		
		namer `months' `unempl'
		stats `r(outcome)' `r(pred)'

		file write myfile ///
		"`months' Months & `r(n)' & `r(mean_f)' & `r(mean_f_hat)' & `r(var_f)'  & `r(var_f_hat)' & `r(cov)' & `cov_6m' & `r(r2)' & `r2_6m' \\ \addlinespace[0.2cm]" _newline

	}
}

* Finish table:
file write myfile ///
	"\addlinespace[1.5ex]" _newline ///
	"\hline \hline \addlinespace[1.5ex]" _newline ///
	"\end{tabular}" _newline ///
	"\end{table}" _newline ///
	"\end{document}"

file close myfile	
